package com.editso.haier.controller.admin;

import com.editso.haier.annon.Admin;
import com.editso.haier.result.Result;
import com.editso.haier.service.AdminBaseService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Admin
@RestController
@RequiresRoles("admin")
public class BaseController {

    private AdminBaseService baseService;

    @Autowired
    public void setBaseService(AdminBaseService baseService) {
        this.baseService = baseService;
    }

    @PostMapping("/tag")
    public Result addTag(@RequestParam(defaultValue = "single") String type,
                          @RequestBody Object tag){
        if ("single".equals(type))
            return baseService.addTags(Arrays.asList(tag));
        else if ("multi".equals(type))
            return baseService.addTags(((List<Object>) tag));
        return Result.failure(tag);
    }
}
